package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;

import beans.HttpConfig;
import beans.HttpResultList;
import beans.LCStoreModel;
import engine.BIEngine0_1.AlgorithmOperator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import utils.SortFile;

/**
 * Servlet implementation class GetFilePath
 */
public class GetFilePath extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetFilePath() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url = request.getParameter("url");
		if (!HttpConfig.fake) {
//			HttpResultList result = AlgorithmOperator.getFilePath(url);
//			HttpResultList result = AlgorithmOperator.getFilePathNew(url);
			HttpResultList result = AlgorithmOperator.getFilePathLocal(url);
			JSONArray aa = JSONArray.fromObject(result.getDatas());
			JSONObject resultObject = new JSONObject();
			resultObject.put("result", result.isResult());
			resultObject.put("message", aa.toString());
			response.getWriter().println(resultObject);
		}else{
//			HttpResultList result = AlgorithmOperator.getFilePath(url);
			HttpResultList result = AlgorithmOperator.getFilePathNew(url);
			JSONObject resultObject = new JSONObject();
			resultObject.put("result", result.isResult());
			resultObject.put("message", result.getMessage());
			response.getWriter().println(resultObject);
		}
	}
	

}
